﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Nuzzle.Managers
{
    public class CharacterManager
    {
        public static Random Rand = new Random(Environment.TickCount);
        public static string[] LettersPairs = { "lo", "la", "li", "wo", "wi", "ka", "ko", "ki", "po",
                                                  "pi", "pa", "aw", "al", "na", "ni", "ny", "no", "ba", "bi",
                                                  "ra", "ri", "ze", "za", "da", "zel", "wo", "-" };

        public static int RandomNumber(int min, int max)
        {
            return Rand.Next(min, max);
        }

        public static string GetRandomName()
        {
            string Name = "";
            for (int i = 0; i <= RandomNumber(2, 4); i++)
            {
                Name += LettersPairs[RandomNumber(0, LettersPairs.Length - 1)];
            }
            Name = Name.ToCharArray()[0].ToString().ToUpper() + Name.Substring(1);
            return Name;
        }

        public static bool ExistName(string nickname)
        {
            lock (Database.DatabaseCache.CharactersCache)
            {
                return Database.DatabaseCache.CharactersCache.FindAll(x => x.Nickname.ToLower() == nickname.ToLower()).Count > 0;
            }
        }
    }
}
